All Questions
Tagged with programmingshell-script
21 questions
1vote
2answers
1kviews
Is there a way to do namespaces like in C for bash?
What I'm talking about is like in C, you get to use namespaces with the statement using namespace blah blah blah, can you do the same thing but in bash?
4votes
2answers
12kviews
Creating a bash script to install packages
I'm quite a newbie when it comes to bash. I'm trying to create a script that checks whether a package is installed or not. If not it will install that package. Not sure what I'm doing tbh. #! /bin/...
0votes
1answer
856views
Bash script printing expression instead of result
I am trying to calculate multiplication of number of arguments and first argument provided by the customer. here the arguments are 10, 15 so total number of arguments is 2. Now i want the shell to ...
1vote
1answer
53views
how to repeat values of B variable till number of A variables are finished
I have infile with values for 2 variables # cat infile A 1 B 2 C D E I want to read variable a & b, so that if $b has null value, it should repeat like 1..2, till all $a values are read. so if I ...
0votes
1answer
178views
Does the shell script interpreter optimize if else chains?
As far as I understand, an interpreter runs code line by line; but I find probable that my reasoning is incorrect. If in this example case the first if line returns true, will the program know to skip ...
0votes
2answers
6kviews
How to get into python environment and run some python commands and return to normal terminal using shell script
Sorry about the title it may not be clear. Here is the complete explanation of my doubt. I am writing the below shell script and expecting the mentioned output. #!/bin/bash python3 print("Hello ...
0votes
0answers
182views
End process but resume bash script?
I am trying to create a script in which part of it runs a command that can only be stopped by the user sending SIGINT to the process. I want the user to be able to press Ctrl+C to end that part of the ...
1vote
0answers
25views
How to give stdout to different program on same line? [duplicate]
I could do it long way i.e cat hi.txt | grep 'important url' > imurl cat hi.txt | grep -v 'not important url' > imnoturl cat hi.txt | otherprogram1 cat hi.txt | otherprogramN However, is there ...
1vote
1answer
730views
How do I pass commands to an external command, from bash?
I would like know if it is possible to enter in an external program and give commands from a bash script. As an example, lets imagine the external program is ipython and I want to give the commands ...
0votes
1answer
584views
Bash Script Time each function and Time total Script Execution Duration
I've written a bash script and would like to implement a timer that will also get the total time of the scripts execution duration and also the time that each loop iteration takes. For example, in the ...
1vote
1answer
536views
The $@ variable is not working in a for loop, trying to iterate through a users list
PROBLEM: I can't get the $@ variable to do what I want in a for loop, the loop only sends one name into the file while looping, it should loop through all the arguments and write them to the file ...
1vote
2answers
3kviews
checking if iptables are set on a system in script [duplicate]
I'm writing a script in bash and I need to check if iptables are set...I have this: if [ `iptables-save | grep '^\-' | wc -l` > 0 ] then echo "Iptables already set, skipping..........!" else ...
2votes
2answers
4kviews
Getting access to a variable inside a sudo clause in a script with EOF
PROBLEM: I need to have a variable here called $user: chown $user:$user "$HOME"/.bashrc but it doesn't have access to it from outside the sudo and EOF: for user in "$@" do if [ "$user" = root ] ...
0votes
1answer
172views
why $($var) gives an error?
I am trying to execute the following code in shell but I am not getting the output as expected. The command is as follows: i=1 echo $($i) I am getting an error: Command not found error I think it ...
0votes
2answers
109views
How to have access to script variables and environmental variables inside a sudo/EOF clause in a script......BASH
PROBLEM: I am struggling with this cp always giving errors because the variables not there... Here is my code: if [ ! -z "$USER1" ] then sudo -u "$USER1" bash <<'EOF' sleep 5 ...